        var transferStore = new Ext.data.JsonStore({
			url: '/weihe/getDTCargo_transferList',
			root: 'datas',
			fields : [{
	        	   name:'transferId',mapping:'id'
	          },{
	        	   name:'transferAmount',mapping:'amount' 
	          },{
				   name:'transferPrice',mapping:'price'
			  },{
				   name:'transferSum',mapping:'sum'
			  },{
				   name:'cargoId',mapping:'cargo', convert:function(v){ 
												return v ? v.id : undefined;}
			  },{
				   name:'transferLocation',mapping:'cargo', convert:function(v){ 
												return v ? v.location : undefined;}
			  },{
				   name:'transferPlace',mapping:'cargo', convert:function(v){ 
												return v ? v.place : undefined;}
			  },{
				   name:'transferCode',mapping:'cargo', convert:function(v){ 
												return v ? v.code : undefined;}
	          },{
	        	   name:'transferName',mapping:'cargo', convert:function(v){ 
												return v ? v.name : undefined;}
	          },{
	        	   name:'transferSpecs',mapping:'cargo', convert:function(v){ 
	        	  								return v ? v.specs : undefined;}
	          },{
	        	   name:'transferUnit',mapping:'cargo', convert:function(v){ 
	        	  								return v ? v.unit : undefined;}
	          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_transferList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        var transferListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_transferList',
			root: 'datas',
			fields : [{
			        	   name:'transferListId',mapping:'id'
			          },{
        				   name:'transferListNum',mapping:'listNum'
        			  },{
        				   name:'transferDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'transferOutDepartment',mapping:'outDepartment'
        			  },{
        				   name:'transferInDepartment',mapping:'inDepartment'
        			  },{
        				   name:'transferOutType',mapping:'outType'
        			  },{
        				   name:'transferInType',mapping:'inType'
        			  },{
        				   name:'transferRemark',mapping:'remark'
        			  },{
        				   name:'transferWarehouse',mapping:'warehouse'
        			  },{
        				   name:'transferInWarehouse',mapping:'inWarehouse'
        			  },{
        				   name:'transferMaker',mapping:'maker'
        			  },{
        				   name:'transferAuditor',mapping:'auditor'
        			  },{
        				   name:'transferHandler',mapping:'handler'
        			  }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_transferList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
    	
    	
    
    	

transfers = function(){
  return{

	  
	  
	  listPanel : function(){
		  
			var listPanel = new Ext.Panel( {
				                    region : 'north',
				                    layout : 'border',
				                    frame  : true,
				                    height : 230,
				                    items  : [transfers.listGrid(),transfers.listForm()]
			                      });
		  
		  return listPanel;
	  	},

	  	  listForm : function(){
		  
			var button_add = new Ext.Button({
				text : '添加',
				handler : function() {
					progressConsole();
					if(listForm.form.isValid()){ 
						var tmp = listForm.form.findField('transferList.warehouse').getValue();
						Ext.getCmp('transferCode').getStore().setBaseParam('location',tmp);
						Ext.getCmp('transferCode').getStore().load({params : {query : '%'}});
						Ext.getCmp('transferName').getStore().setBaseParam('location',tmp);
						Ext.getCmp('transferName').getStore().load({params : {query : '%'}});
						Ext.getCmp("transfersForm").buttons[0].enable();
						Ext.getCmp("transfersForm").buttons[1].enable();
						Ext.getCmp("transfersForm").buttons[2].enable();
						if (listForm.form.findField("transferListId").getValue() == "") {
							 listForm.form.submit({
							     url : '/weihe/add_transferList',
							     success : function(form, action) {
								      if (action.result.deny) {
										 Ext.Msg.alert('错误', action.result.msg);
								  	  }else{
									        Ext.Msg.alert('消息', action.result.msg, function() {
									        listForm.form.reset();
									        Ext.getCmp("tgrid").getStore().removeAll();
										    Ext.getCmp("transfersForm").form.findField('transferList.id').setValue(action.result.transferList_id);
										    Ext.getCmp("transferListGrid").getStore().load({params : {start : action.result.total-1, limit :6}});;
									        })
								       }
							     },
								 failure : function(form, action) {
		      							Ext.Msg.alert('错误', action.result.msg);
		      						}
						      })
						}else {
								listForm.form.submit({
									url : '/weihe/update_transferList',
									success : function(form, action) {
										if (action.result.deny) {
											 Ext.Msg.alert('错误', action.result.msg);
								  	    }else{
											Ext.Msg.alert('消息', action.result.msg, function() {
												Ext.getCmp("transferListGrid").getStore().reload();
											})
										}
								   },
									 failure : function(form, action) {
		      							Ext.Msg.alert('错误', action.result.msg);
		      						}
								})
						}
					}else{
						Ext.Msg.alert('提示','请输入相关内容');
					}
				}
			});

		var button_clear = new Ext.Button({
			text : '清空',
			handler : function() {
			
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("transfersForm").form.reset();
			Ext.getCmp("transfersForm").buttons[0].disable();
			Ext.getCmp("transfersForm").buttons[1].disable();
			Ext.getCmp("transfersForm").buttons[2].disable();
			Ext.getCmp("tgrid").getStore().removeAll();
			}
		});

		var button_del = new Ext.Button({
			text : '删除',
			handler : function() {
				var id = listForm.form.findField('transferListId').getValue();
				if (id == '') {
					Ext.Msg.alert('提示', '请选择需要删除的信息!');
				} else {
					progressConsole();
					Ext.Ajax.request({
						url : '/weihe/delete_transferList',
						success : function(response) {
							var json = Ext.decode(response.responseText);
							if (json.success) {
							  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
						      }else{
								Ext.Msg.alert('消息', json.msg, function() {
									Ext.getCmp("transferListGrid").getStore().load({params : {start : 0, limit : 6}});
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
								});
						      }
							}else{
								Ext.Msg.alert('消息', json.msg);
							}
						},
						failure : function() {
							Ext.Msg.alert('错误', '删除失败!');
						},
						params: { 'transferList.id' : listForm.form.findField('transferListId').getValue() }
					});
				}
			}
		});
		
		  
		  var whComboData = new Ext.data.SimpleStore({
				fields : ['value','text'],
				data : [['A','A'],['B','B'],['C','C'],['报废','报废']]
			});
		  
				var listForm = new Ext.form.FormPanel({
				id : 'transferListForm',
				title : '产品销售信息',
				frame : true,
				region: 'east',
				width : 300,
				autoScroll : true,
				collapseMode :'mini',
				collapsible : true,
				labelAlign : 'right',
				labelWidth : 60,
				defaultType : 'textfield',
					defaults : {
					width : 200
				},
				items : [{
					id: 'transferListId',
					xtype : 'hidden',
					name : 'transferList.id'
				},{
					id: 'transferListNum',
					xtype : 'hidden',  
	        	    name: "transferList.listNum"
				},{
					id: 'transferDate',
	              xtype: 'datefield',
	              fieldLabel: "日期", 
	              format : 'Y-m-d',
	  			allowBlank:false,
	              name: "transferList.date"
				},{
					id:'transferWarehouse',
					fieldLabel : '转出仓库',
					hiddenName : 'transferList.warehouse',
					xtype : 'combo',
					store : whComboData,
					emptyText : '请选择',
					mode : 'local',
					triggerAction : 'all',
					allowBlank:false,
					editable: false,
					valueField : 'value',
					displayField : 'text'
				},{
					id:'transferInWarehouse',
					fieldLabel : '转入仓库',
					hiddenName : 'transferList.InWarehouse',
					xtype : 'combo',
					store : whComboData,
					emptyText : '请选择',
					mode : 'local',
					triggerAction : 'all',
					allowBlank:false,
					editable: false,
					valueField : 'value',
					displayField : 'text'
				},{
					id: 'transferOutDepartment',
					 fieldLabel: "转出部门",
	             name: "transferList.OutDepartment"
				},{
					id: 'transferInDepartment',
					 fieldLabel: "转入部门",
	             name: "transferList.InDepartment"
				},{
					id: 'transferOutType',
					 fieldLabel: "出库类别",
	               name: "transferList.OutType"
				},{
					id: 'transferInType',
					 fieldLabel: "入库类别",
	               name: "transferList.InType"
				},{
					id: 'transferHandler',
					 fieldLabel: "经手人",
	              name: "transferList.handler"
				},{
					id: 'transferRemark',
					 fieldLabel: "备注",
	              name: "transferList.remark"
				},{
					id: 'transferMaker',
					 fieldLabel: "制单人",
	             name: "transferList.maker"
				}],
				buttons : [button_add,button_clear,button_del]
		});
		  
		  return listForm;
	},  
		  
		  
	listGrid : function(){
		  
			var pageToolBar = new Ext.PagingToolbar({
				pageSize : 6,
				store : transferListStore,
				displayInfo : true,
				displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
			    emptyMsg : "没有记录显示!",
			    firstText : '首页',
			    prevText : '上一页',
			    nextText : '下一页',
			    lastText : '尾页',
			    beforePageText : '第',
			    afterPageText : '页,共{0}页'
			});


			var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
			
			   
		   var listGrid = new Ext.grid.GridPanel({
			   id:'transferListGrid',
			   region: 'center',
			   minColumnWidth : 35,
			   loadMask : {msg:'正在加载数据，请稍侯...'},
			   store : transferListStore,
			   columns: [
			             {header : '单据号', dataIndex : 'transferListNum'},
			             {header : '日期', dataIndex : 'transferDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
			             {header : '转出部门', dataIndex : 'transferOutDepartment'},
			             {header : '转入部门', dataIndex : 'transferInDepartment'},
			             {header : '转出仓库', dataIndex : 'transferWarehouse'},
			             {header : '转入仓库', dataIndex : 'transferInWarehouse'},
			             {header : '出库类别', dataIndex : 'transferOutType'},
			             {header : '入库类别', dataIndex : 'transferInType'},
			             {header : '经手人', dataIndex : 'transferHandler'},
			             {header : '备注', dataIndex : 'transferRemark'},
			             {header : '制单人', dataIndex : 'transferMaker'},
			             {header : '审核人', dataIndex : 'transferAuditor'}
			             ],
	       sm : rowSelectionModel,
	       listeners :{ 
				   'rowclick':function(grid, rowIndex, event) {
				   		var record = grid.getStore().getAt(rowIndex);
				   		Ext.getCmp("transferListForm").form.loadRecord(record);
				   		Ext.getCmp("transfersForm").form.findField('transferList.id').setValue(record.id);
				   		Ext.getCmp("transfersForm").buttons[0].enable();
						Ext.getCmp("transfersForm").buttons[1].enable();
						Ext.getCmp("transfersForm").buttons[2].enable();
						Ext.getCmp('transferCode').getStore().setBaseParam('location',record.get('transferWarehouse'));
						Ext.getCmp('transferCode').getStore().load({params : {query : '%'}});
						Ext.getCmp('transferName').getStore().setBaseParam('location',record.get('transferWarehouse'));
						Ext.getCmp('transferName').getStore().load({params : {query : '%'}});
						Ext.getCmp("transferListForm").buttons[0].setText('修改');
						Ext.getCmp('transferCode').getStore().baseParams = {'location': record.get('transferWarehouse')};
						Ext.getCmp('transferCode').getStore().reload();
				   		Ext.getCmp('transferName').getStore().baseParams = {'location': record.get('transferWarehouse')};
						Ext.getCmp("tgrid").getStore().baseParams = {'transferList.id': record.id};
						Ext.getCmp("tgrid").getStore().load({params : {start : 0, limit : 6}});
			   		}
			   },
			  bbar : pageToolBar
	});
			return listGrid;
		},
		  
		
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : transferStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'tgrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : transferStore,
		   columns: [
		             {header : '产品编号', dataIndex : 'transferCode', menuDisabled : true},
		             {header : '产品名称', dataIndex : 'transferName'},
		             {header : '规格型号', dataIndex : 'transferSpecs', menuDisabled : true},
		             {header : '单位', dataIndex : 'transferUnit', menuDisabled : true},
		             {header : '所在仓库', dataIndex : 'transferLocation', menuDisabled : true},
		             {header : '存放位置', dataIndex : 'transferPlace', menuDisabled : true},
		             {header : '数量', dataIndex : 'transferAmount', menuDisabled : true},
		             {header : '单价', dataIndex : 'transferPrice',sortable : true},
		             {header : '金额', dataIndex : 'transferSum',sortable : true}
		             
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("transfersForm").form.loadRecord(record);
			   Ext.getCmp("transfersForm").buttons[0].setText('修改');
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	transfersForm : function(){
		
		var codestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByCode_depotList',
			root: 'codes',
			totalProperty: 'count',
			fields: ['code']
		});
		
		var namestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByname_depotList',
			root: 'names',
			totalProperty: 'count',
			fields: ['name']
		});
		
		var codeCombo = {
				id : 'transferCode',
				xtype: 'combo',
				fieldLabel: '产品编号',
				store: codestore,
				typeAhead: false,
				name : 'cargo.code',
				loadingText: '查找中...',
				emptyText: '请输入3位以上编号', 
				minChars: 3,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'code',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getCode_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									  transfersForm.form.findField('transferName').setValue(json.name);
									  transfersForm.form.findField('transferSpecs').setValue(json.specs);
									  transfersForm.form.findField('transferUnit').setValue(json.unit);
									  transfersForm.form.findField('transferPrice').setValue(json.price);
									  transfersForm.form.findField('transferPlace').setValue(json.place);
									  transfersForm.form.findField('cargo.id').setValue(json.id);
									},
								params : 'query=' + record.get('code')
							});
				    }
				}
		}
		var nameCombo = {
				id : 'transferName',
				xtype: 'combo',
				fieldLabel: '产品名称',
				store: namestore,
				typeAhead: false,
				name : 'cargo.name',
				loadingText: '查找中...',
				emptyText: '请输入产品名称', 
				minChars: 2,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'name',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getName_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									 transfersForm.form.findField('transferCode').setValue(json.code);
									  transfersForm.form.findField('transferSpecs').setValue(json.specs);
									  transfersForm.form.findField('transferUnit').setValue(json.unit);
									  transfersForm.form.findField('transferPrice').setValue(json.price);
									  transfersForm.form.findField('transferPlace').setValue(json.place);
									  transfersForm.form.findField('cargo.id').setValue(json.id);
									},
								params : 'query=' + record.get('name')
							});
				    }
				}
		}


		var button_add = new Ext.Button({
			text : '添加',
			disabled : true,
			handler : function() {

					progressConsole();
				if(transfersForm.form.isValid()){ 	
					if (transfersForm.form.findField("dt_Cargo.id").getValue() == "") {
						transfersForm.form.submit({
						  url : '/weihe/addDTCargo_transferList',
						   success : function(form, action) {
								  if (action.result.deny) {
											 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										 var i = transfersForm.form.findField('transferList.id').getValue();
										   transfersForm.form.reset();
										   transfersForm.form.findField('transferList.id').setValue(i);
										   Ext.getCmp("tgrid").getStore().baseParams = {'transferList.id': i};
										   Ext.getCmp("tgrid").getStore().load({params : {start : 0, limit : 6}});
										
								})
							  }
						    },
							failure : function(form, action) {
								Ext.Msg.alert('错误', action.result.msg);
						    }
					    })
					}else {
						transfersForm.form.submit({
							  url : '/weihe/updateDTCargo_transferList',
							   success : function(form, action) {
								  if (action.result.deny) {
									Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = transfersForm.form.findField('transferList.id').getValue();
										transfersForm.form.reset();
										 transfersForm.form.findField('transferList.id').setValue(i);
										Ext.getCmp("tgrid").getStore().reload();
										    transfersForm.buttons[0].setText('添加');
										
									})
								  }
							    },
								failure : function(form, action) {
									Ext.Msg.alert('错误', action.result.msg);
							    }
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = transfersForm.form.findField('transferList.id').getValue();
			transfersForm.form.reset();
			transfersForm.form.findField('transferList.id').setValue(i);
		    transfersForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = transfersForm.form.findField('dt_Cargo.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteDTCargo_transferList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
								var i = transfersForm.form.findField('transferList.id').getValue();
								transfersForm.form.reset();
								transfersForm.form.findField('transferList.id').setValue(i);
								transfersForm.buttons[0].setText('添加');
						   }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("tgrid").getStore().load({params : {start : 0, limit : 6}});
								var i = transfersForm.form.findField('transferList.id').getValue();
								transfersForm.form.reset();
								transfersForm.form.findField('transferList.id').setValue(i);
								transfersForm.buttons[0].setText('添加');
							});
						}
					  }
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : {'dt_Cargo.id': id , 'transferList.id':transfersForm.form.findField('transferList.id').getValue()}
				});
			}
		}
	});
	
		var transfersForm = new Ext.form.FormPanel({
			id : 'transfersForm',
			title : '货物信息',
			frame : true,
			width : 300,
			region : 'east',
			autoScroll : true,
			collapseMode :'mini',
			collapsible : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'transferId',
				xtype : 'hidden',
				name : 'dt_Cargo.id'
			},{
				xtype : 'hidden',
				name : 'transferList.id'
			},{ 
				xtype : 'hidden',
				name : 'cargo.id'
			},codeCombo ,nameCombo
			 ,{
				id:'transferSpecs',
				fieldLabel : '规格型号',
				name : 'cargo.specs',
				readOnly: true
			},{
				id:'transferUnit',
				fieldLabel : '单位',
				name : 'cargo.unit',
				readOnly: true
			},{
				id:'transferPlace',
				fieldLabel : '存放位置',
				name : 'cargo.place',
				readOnly: true
			},{
				id:'transferPrice',
				fieldLabel : '单价',
				name : 'dt_Cargo.price',
				readOnly: true
			},{
				id:'transferAmount',
				fieldLabel : '数量',
				name : 'dt_Cargo.amount',
				allowBlank:false,
				blankText:'请输入数量',
				regex : /^[1-9]\d*$/,
			    regexText:'请输入有效的数量'  
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return transfersForm;
	}
  }
}();








